package com.example.demo.controller;

import com.example.demo.entity.GoodsSkusCombinations;
import com.example.demo.service.GoodsSkusCombinationsService;
import com.example.demo.controller.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/goods_skus_combinations")
public class GoodsSkusCombinationsController {

    @Autowired
    private GoodsSkusCombinationsService goodsSkuCombinationsService;

    /**
     * 创建商品SKU组合
     *
     * @param goodsSkuCombinations 商品SKU组合信息
     * @return 创建成功的商品SKU组合信息
     */
    @PostMapping
    public ResponseResult<GoodsSkusCombinations> createGoodsSkuCombinations(@RequestBody GoodsSkusCombinations goodsSkuCombinations) {
        GoodsSkusCombinations created = goodsSkuCombinationsService.createGoodsSkuCombinations(goodsSkuCombinations);
        return ResponseResult.success(created);
    }

    /**
     * 更新商品SKU组合信息
     *
     * @param id 商品ID
     * @param goodsSkuCombinations 商品SKU组合信息
     * @return ResponseResult<Boolean> 更新结果
     */
    @PostMapping("/{id}")
    public ResponseResult<Boolean> updateGoodsSkuCombinations(@PathVariable Integer id, @RequestBody GoodsSkusCombinations goodsSkuCombinations) {
        goodsSkuCombinations.setId(id);
        boolean result = goodsSkuCombinationsService.updateGoodsSkuCombinations(goodsSkuCombinations);
        return ResponseResult.success(result);
    }

    @PostMapping("/{id}/delete")
    public ResponseResult<Boolean> deleteGoodsSkuCombinations(@PathVariable Integer id) {
        boolean result = goodsSkuCombinationsService.deleteGoodsSkuCombinations(id);
        return ResponseResult.success(result);
    }

    @GetMapping("/{id}")
    public ResponseResult<GoodsSkusCombinations> getGoodsSkuCombinationsById(@PathVariable Integer id) {
        GoodsSkusCombinations goodsSkuCombinations = goodsSkuCombinationsService.getGoodsSkuCombinationsById(id);
        return ResponseResult.success(goodsSkuCombinations);
    }
}
